/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.usc.cs523.client;

/**
 *
 * @author haoxu
 */
public class ItemManager {

    public static double period = 10000;
    Rival player;
    PanelManager panelManager;

    public ItemManager(Rival player) {
        this.player = player;
    }

    ItemManager(Rival myself, PanelManager panelManager) {
        this.player = player;
        this.panelManager = panelManager;
    }

    public void powerup() {
        new Thread() {

            @Override
            public void run() {
                player.Power_Factor *= 2.0f;
                long current = System.currentTimeMillis();
                while (System.currentTimeMillis() - current <= period) {
//                    System.out.println(player.Speed_Factor);
                    int left = (int) (period - (System.currentTimeMillis() - current) % 1000);
                    if (left == 0) {
                        panelManager.setMessage("Time Left " + left);
                    }
                }
                panelManager.setMessage("Back To Normal");
                player.Power_Factor /= 2.0f;
            }
        }.start();
    }

    public void speedup() {

        new Thread() {

            @Override
            public void run() {
                player.Speed_Factor *= 2.0f;
                long current = System.currentTimeMillis();
                while (System.currentTimeMillis() - current <= period) {
//                    System.out.println(player.Speed_Factor);
                    int left = (int) (period - (System.currentTimeMillis() - current) % 1000);
                    if (left == 0) {
                        panelManager.setMessage("Time Left " + left);
                    }
                }
                panelManager.setMessage("Back To Normal");
                player.Speed_Factor /= 2.0f;
            }
        }.start();
    }

    public void healup() {
        player.HP = Math.max(player.HP + 10, 100);
    }

    public void magicup() {
        player.MP = Math.max(player.MP + 10, 100);
    }

    public void invisible() {
    }
}
